﻿// 创建人  ：zhongjian
// 创建时间：2010年5月24日
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Data;
using System.Configuration;
using WF_Business;

namespace ExtBusiness.Admin
{
    /// <summary>
    /// 系统信息操作类
    /// </summary>
    /// <!--add by zhongjian 20100524-->
    public class SystemManager
    {
        string strSql = string.Empty;//SQL语句字符
        DataTable dtTemp = new DataTable();

        /// <summary>
        /// 获取优先级分配
        /// </summary>
        /// <param name="strBusinessType">业务类型</param>
        /// <param name="strUnitName">单位名称</param>
        /// <param name="strStartDate">开始时间</param>
        /// <param name="strEndDate">结束时间</param>
        /// <returns></returns>
        /// <!--addby zhongjian 20100524-->
        public DataTable GetPriority(string strBusinessType, string strUnitName,string strStartDate,string strEndDate)
        {
            strSql = string.Format(@"select Rownum as num,f.wname,i.Name,to_char(i.accepted_time,'yyyy-mm-dd hh24:mi:ss') accptime,i.iid,i.priority  
                                    from st_instance i,st_workflow f Where i.wid=f.wid and i.status='1' and i.isdelete <>1 ");
            if (!string.IsNullOrEmpty(strUnitName))
                strSql += string.Format(" and i.name like '%{0}%'", strUnitName);
            if (!string.IsNullOrEmpty(strStartDate))
                strSql += string.Format(" and i.ACCEPTED_TIME>=to_date('{0}','yyyy-mm-dd')", strStartDate);
            if (!string.IsNullOrEmpty(strEndDate))
                strSql += string.Format(" and i.ACCEPTED_TIME<to_date('{0}','yyyy-mm-dd')+1", strEndDate);
            if (!string.IsNullOrEmpty(strBusinessType))
                strSql += string.Format(" and f.wname = '{0}'", strBusinessType);

            SysParams.OAConnection().RunSql(strSql, out dtTemp);
            return dtTemp;
        }

        /// <summary>
        /// 判断是否用户是管理员
        /// </summary>
        /// <param name="CurUserId">用户id</param>
        /// <returns></returns>
        public static bool IsSystemManager(string CurUserId)
        {
            bool returnValue = false;
            string manageUser = ConfigurationManager.AppSettings["SystemManUser"];
            string strSql = string.Format("select userid from st_user_department t where order_id='{0}'", manageUser);
            DataTable dtTemp;
            SysParams.OAConnection().RunSql(strSql, out dtTemp);
            DataRow[] rowUsers = dtTemp.Select("userid='" + CurUserId + "'");
            if (rowUsers.Length > 0)
                returnValue = true;
            return returnValue;
        }

        ///返回当前人员是否管理员或者数据维护组成员
        /// <summary>
        /// 根据用户ID查询用户是否为系统管理员或者监察室
        /// </summary>
        /// 如果是 返回 true
        /// <param name="userid">用户ID</param>
        /// <returns></returns>
        /// <!--按角色判断该用户是否管理员 update by zhongjian 20100205-->
        public static bool IsSystemUser(string userid)
        {
            string strSql = string.Format(@"select id from st_user_group where GID = (select groupid from st_group where group_name = '管理员') and userid = '{0}'", userid);
            DataTable dtTemp;
            SysParams.OAConnection().RunSql(strSql, out dtTemp);
            bool isTrue = false;
            if (dtTemp.Rows.Count > 0)
                isTrue = true;
            return isTrue;

        }

        /// <summary>
        /// 根据用户ID查询用户是否为系统管理部门
        /// </summary>
        /// 如果是 返回 true
        /// <param name="userid">用户ID</param>
        /// <returns></returns>
        public static bool IsSystemManById(string userid)
        {
            string strSql = "select t.order_id  from st_user_department t where t.userid = '" + userid + "'";
            DataTable dt;
            SysParams.OAConnection().RunSql(strSql, out dt);
            string SystemManUser = System.Configuration.ConfigurationManager.AppSettings["SystemManUser"].ToString();
            bool isTrue = false;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                if (SystemManUser == dt.Rows[i][0].ToString())
                {
                    isTrue = true;//是系统管理员
                    break;
                }
            }
            return isTrue;
        }

    }
}
